﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/admin/list_view.master" %>

<script runat="server">
    void Page_Init(object o, EventArgs e)
    {
        if (null != Session["BranchID"])
        {
            ds2.FilterExpression = string.Format("BranchID={0}", Session["BranchID"]);
        }
        else
        {
            ds2.FilterExpression = string.Format("BranchID={0}", 0);
        }
        
        if (null != Session["ZoneID"])
        {
            ds3.FilterExpression = string.Format("ZoneID={0}", Session["ZoneID"]);
        }
        else
        {
            ds3.FilterExpression = string.Format("ZoneID={0}", 0);
        }
        
        if (!IsPostBack)
        {
            ds2.FilterExpression = string.Format("BranchID={0}", 0);
            ds3.FilterExpression = string.Format("ZoneID={0}", 0);
        }
    }
    
    void clickme(object o, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);
       // mylabel.Text = "click alrady";
       // timerbox.Text = DateTime.Now.ToString();
        
    }

    void MakeChanged(Object sender,  EventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;

        int t = grid.FocusedRowIndex;
        if (t > -1)
        {
            object id = grid.GetRowValues(t, new string[] { "BranchID" });
            //object name = grid.GetRowValues(t, new string[] { "Name" });
            // mylabel.Text = "Selection:" + id.ToString();
            
            Session["BranchID"] = id;
            int idn = int.Parse(id.ToString());
            if (idn > 0)
            {
              
            } 
            
            ds2.FilterExpression = string.Format("BranchID={0}", Session["BranchID"]);

            grid2.Selection.UnselectAll();
            grid2.PageIndex = 0;
            grid2.DataBind();
            
            
            
            
            //this.dsXXModel.FilterExpression = "BranchID=" + o;
            //DataBind();
        }
    }


    protected void grid2_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.BoZone));
        }
    }

    protected void grid2_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
    }

    protected void grid2_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
    }

    protected void grid2_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        int id = int.Parse(Session["BranchID"].ToString());
        e.NewValues["BranchID"] = id;
    }


    protected void grid3_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.BoArea));
        }
    }
    protected void grid3_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
    }
    protected void grid3_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
    }
    protected void grid3_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        int id = int.Parse(Session["BranchID"].ToString());
        int zid = int.Parse(Session["ZoneID"].ToString());
        e.NewValues["BranchID"] = id;
        e.NewValues["ZoneID"] = zid;
    }
    protected void grid3_DataSelect(object sender, EventArgs e)
    {
        Session["ZoneID"] = (sender as ASPxGridView).GetMasterRowKeyValue();
        ds3.FilterExpression = string.Format("ZoneID={0}", Session["ZoneID"]);

    }


    
    </script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style>
    div {font-size:10px;font-family:Verdana;}
    #COLORBOX {

		display:none;
		width:560px;
		border:10px solid #666;
		border:10px solid rgba(82, 82, 82, 0.698);
		-moz-border-radius:8px;
		-webkit-border-radius:8px;
	}
    .cbox {height:50px;width:50px;}



    </style>
    <script type="text/javascript">
        var el;
        function putColor(v) {
            if (el)
                el.style.backgroundColor = v;
            colorBOX.text = v;
            }

        function showColor(e) {
            el = e;
            $("#COLORBOX").overlay({

                // custom top position
                top: 260,

                // some mask tweaks suitable for facebox-looking dialogs
                mask: {

                    // you might also consider a "transparent" color for the mask
                    color: '#fff',

                    // load mask a little faster
                    loadSpeed: 200,

                    // very transparent
                    opacity: 0.5
                },
                // disable this for modal dialog-type of overlays
                closeOnClick: false,
                // load it immediately after the construction
                load: true

            });


        }

    </script>
</asp:Content>

<asp:Content ID="title1" ContentPlaceHolderID="Title1" Runat="Server">
<table width=100% cellpadding="4">
    <tr>
    <td align=left class="bb">
        Branch List
    </td>
    <td align=right class="bb">
    </td>
    </tr>
</table>
</asp:Content>
<asp:Content ID="title2" ContentPlaceHolderID="Title2" Runat="Server">
<table width=100% cellpadding="4">
    <tr>
    <td align=left class="bb">
        Branch Zone Manager
    </td>
    <td align=right class="bb">
        [ <a href="javascript:grid2.AddNewRow();"> + </a> ]
    </td>
    </tr>
</table>
</asp:Content>
<asp:Content ID="title3" ContentPlaceHolderID="Title3" Runat="Server">

</asp:Content>

<asp:Content ID="Page1" ContentPlaceHolderID="Page1" Runat="Server">
<wilson:DataSource ID="ds1" TypeName="Touchmax.BoBranch" KeyMember="BranchID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<dxwgv:ASPxGridView ID="grid1" ClientInstanceName="grid1" runat="server" DataSourceID="ds1" KeyFieldName="BranchID" 
       OnFocusedRowChanged="MakeChanged" Width="100%" AutoGenerateColumns="False" EnableCallBacks="False">
                <SettingsPager Mode="ShowAllRecords"/>
                <Columns>
                    <dxwgv:GridViewDataColumn FieldName="BranchName" VisibleIndex="1" SortIndex="1" SortOrder="Descending">
                    </dxwgv:GridViewDataColumn>
                </Columns>
                <Settings ShowGroupPanel="False" ShowFooter="False" ShowTitlePanel="false" ShowColumnHeaders="False" />
                <SettingsBehavior AllowMultiSelection="false" AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="true" />
            </dxwgv:ASPxGridView>
</asp:Content>
<asp:Content ID="Page2" ContentPlaceHolderID="Page2" Runat="Server">
<wilson:DataSource ID="dsBranch" TypeName="Touchmax.BoBranch" KeyMember="BranchID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<wilson:DataSource ID="ds3" TypeName="Touchmax.BoArea" KeyMember="AreaID" FilterExpression="1=0" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<wilson:DataSource ID="dsCity" TypeName="Touchmax.DdCity" KeyMember="CityID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<asp:SqlDataSource ID="dsPickTech" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select EmployeeID, Firstname  from [BoEmployee] where EmployeeGroupID=119 order by firstname"  />
<asp:SqlDataSource ID="dsPickPrimaryColor" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1012 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
 
<wilson:DataSource ID="ds2" TypeName="Touchmax.BoZone" KeyMember="ZoneID" FilterExpression="BranchID=0" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<dxwgv:ASPxGridView ID="grid2" ClientInstanceName="grid2" runat="server" DataSourceID="ds2" KeyFieldName="ZoneID" 
        Width="100%" AutoGenerateColumns="False"  EnableCallBacks="False" OnInit="grid2_Init" OnInitNewRow="grid2_InitNewRow" OnRowUpdating="grid2_RowUpdating" OnRowInserting="grid2_RowInserting">
                <SettingsPager Mode="ShowAllRecords"/>
                <Columns>
                    <dxwgv:GridViewCommandColumn VisibleIndex="0" Width="80">
                        <EditButton Visible="True" />
                    </dxwgv:GridViewCommandColumn>           
                    <dxwgv:GridViewDataColumn Caption="Zone Name" Width="200" FieldName="ZoneName" VisibleIndex="2"></dxwgv:GridViewDataColumn>
                    <dxwgv:GridViewDataComboBoxColumn Caption="Primary Technician"  FieldName="Tech1ID" VisibleIndex="3">
                        <PropertiesComboBox DataSourceID="dsPickTech" TextField="FirstName" ValueField="EmployeeID" EnableSynchronization="False"  EnableIncrementalFiltering="True"></PropertiesComboBox>
                    </dxwgv:GridViewDataComboBoxColumn>         
                    <dxwgv:GridViewDataComboBoxColumn Caption="Secondary Technician"  FieldName="Tech2ID" VisibleIndex="4">
                        <PropertiesComboBox DataSourceID="dsPickTech" TextField="FirstName" ValueField="EmployeeID" EnableSynchronization="False"  EnableIncrementalFiltering="True"></PropertiesComboBox>
                    </dxwgv:GridViewDataComboBoxColumn>         
           
                                        <dxwgv:GridViewDataComboBoxColumn Caption="Service Day" FieldName="WorkDay" VisibleIndex="9">
                                            <PropertiesComboBox EnableSynchronization="False"  EnableIncrementalFiltering="True">
                                                <Items>
                                                <dxe:ListEditItem Text="Monday" Value="Monday"  />
                                                <dxe:ListEditItem Text="Tuesday" Value="Tuesday"/>
                                                <dxe:ListEditItem Text="Wednesday" Value="Wednesday"/>
                                                <dxe:ListEditItem Text="Thursday" Value="Thursday"/>
                                                <dxe:ListEditItem Text="Friday" Value="Friday" />
                                                <dxe:ListEditItem Text="Saturday" Value="Saturday" />
                                                <dxe:ListEditItem Text="Sunday" Value="Sunday" />
                                                </Items>
                                            </PropertiesComboBox>
                                        </dxwgv:GridViewDataComboBoxColumn>         
                    <dxwgv:GridViewDataComboBoxColumn width="70"  Caption="Display Color"  FieldName="DisplayColor" VisibleIndex="7">
                        <PropertiesComboBox DataSourceID="dsPickPrimaryColor" TextField="Code" ValueField="Code" EnableSynchronization="False"  EnableIncrementalFiltering="True">
                        </PropertiesComboBox>
                        <DataItemTemplate>
                            <div style='height:20px;background:<%# Eval("DisplayColor")%>'></div>
                        </DataItemTemplate>
                        <EditItemTemplate>
                            <div style="display:none">
                                <dxe:ASPxTextBox runat="server" ID="colorBOX" ClientInstanceName="colorBOX" Text='<%# Bind("DisplayColor") %>' ></dxe:ASPxTextBox>
                            </div>
                            <div style='text-align:center;width:80px;height:20px;background:<%# Eval("DisplayColor")%>' onclick="showColor(this);">...</div>
                            
                        </EditItemTemplate>
                    </dxwgv:GridViewDataComboBoxColumn>         
                    </Columns>
                    <Templates>
                        <DetailRow>					
					            <br />Area Setup<br />
                                <dxwgv:ASPxGridView ID="detailGrid" runat="server" DataSourceID="ds3" 
                                    KeyFieldName="AreaID" Width="100%" 
                                    OnBeforePerformDataSelect="grid3_DataSelect" OnInit="grid3_Init" OnRowUpdating="grid3_RowUpdating" OnRowInserting="grid3_RowInserting">
                                    <%-- BeginRegion Grid Columns --%>
                                    <SettingsEditing Mode="Inline" />
                                    <Columns>
                                        <dxwgv:GridViewCommandColumn VisibleIndex="0" Width="160">
                                            <EditButton Visible="True" />
                                            <NewButton Visible="True" />
                                        </dxwgv:GridViewCommandColumn>           

                                        <dxwgv:GridViewDataComboBoxColumn Caption="City" FieldName="CityID" VisibleIndex="2">
                                            <PropertiesComboBox DataSourceID="dsCity" TextField="CityName" ValueField="CityID" EnableSynchronization="False"  EnableIncrementalFiltering="True"></PropertiesComboBox>
                                        </dxwgv:GridViewDataComboBoxColumn>         
                                        <dxwgv:GridViewDataSpinEditColumn width="70" Caption="Households" FieldName="HouseHold" VisibleIndex="4"></dxwgv:GridViewDataSpinEditColumn>
                                         <dxwgv:GridViewDataSpinEditColumn width="70" Caption="Rates Factor" FieldName="PriceFactor" VisibleIndex="6"></dxwgv:GridViewDataSpinEditColumn>
                                        <dxwgv:GridViewDataColumn Caption="Zip Code" width="70" FieldName="PostCode" VisibleIndex="1" />                            
                                    
                                    </Columns>
                                    <%-- EndRegion --%>
                                              
                                    <SettingsDetail IsDetailGrid="true"/>
                                </dxwgv:ASPxGridView>
                        </DetailRow>
                    </Templates>
                    <SettingsDetail ShowDetailRow="true"/>                


                    <SettingsEditing Mode="Inline" />
      
                <Settings ShowGroupPanel="False" ShowFooter="False" ShowTitlePanel="false" ShowColumnHeaders="true" />
                <SettingsBehavior ConfirmDelete="True" AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="true" />
            </dxwgv:ASPxGridView>
</asp:Content>
<asp:Content ID="Page3" ContentPlaceHolderID="Page3" Runat="Server">

    <div id="COLORBOX">
    <table cellspacing=10>
    <tr>
        <td class="cbox close" style="background:#DDD9C3;" onclick="putColor('#DDD9C3');"></td><td class="cbox close" style="background:#8DB3E2;" onclick="putColor('#8DB3E2');"></td><td class="cbox close" style="background:#B8CCE4;" onclick="putColor('#B8CCE4');"></td><td class="cbox close" style="background:#E5B9B7;" onclick="putColor('#E5B9B7');"></td><td class="cbox close" style="background:#D7E3BC;" onclick="putColor('#D7E3BC');"></td><td class="cbox close" style="background:#CCC1D9;" onclick="putColor('#CCC1D9');"></td><td class="cbox close" style="background:#B7DDE8;" onclick="putColor('#B7DDE8');"></td><td class="cbox close" style="background:#FBD5B5;" onclick="putColor('#FBD5B5');"></td>
    </tr>
    <tr>
        <td class="cbox close" style="background:#C4BD97;" onclick="putColor('#C4BD97');"></td><td class="cbox close" style="background:#548DD4;" onclick="putColor('#548DD4');"></td><td class="cbox close" style="background:#95B3D7;" onclick="putColor('#95B3D7');"></td><td class="cbox close" style="background:#D99694;" onclick="putColor('#D99694');"></td><td class="cbox close" style="background:#C3D69B;" onclick="putColor('#C3D69B');"></td><td class="cbox close" style="background:#B2A2C7;" onclick="putColor('#B2A2C7');"></td><td class="cbox close" style="background:#92CDDC;" onclick="putColor('#92CDDC');"></td><td class="cbox close" style="background:#FAC08F;" onclick="putColor('#FAC08F');"></td>
    </tr>
    </table>
    </div>


</asp:Content>




